package util::iptables;

use strict;

sub checkip
{
	my $ip = shift;
	my @droped_ip;
	open my $iplist, "iptables -L -n|" or die "$!\n";
	while(my $line = <$iplist>)
	{
		next unless $line =~ m/^DROP/;
		push @droped_ip,(split m/\s+/, $line)[3];
	}
	close $iplist;
	for my $i (@droped_ip)
	{
		return 1 if $i =~ m/$ip/;
	}
	return 0;
}

sub drop
{
	my $ip = shift;
	system("iptable -A INPUT -s $ip -p tcp --dport 80 -j DROP");
}

sub deldrop
{
	my $ip = shift;
	system("iptable -D INPUT -s $ip -p tcp --dport 80 -j DROP");
}